<template>
    <div class="login">
        <div class=" login-container" v-if="hide">
            <div class="login-wrap">
                <div class="logo">
                    <img src="../../assets/image/logo.png" />
                    <p>奢批数字供应链系统</p>
                </div>
                <ul class="dlfs-ul">
                    <li :class="activeClass == index ? 'active' : ''" v-for="(itme, index) in loginTab" :key="index" @click="onTab(index)">{{ itme }}</li>
                </ul>
                <div class="dlfs-content">
                    <el-form v-show="signUpTab == false" class="" el-form ref="forgets" :model="forgets" :rules="loginRule">
                        <div v-if="activeClass == 0" class="dlfs-wrap clearFix" style="display: block;">
                            <el-form-item class="layui-form-item margin-top-40" el-form-item prop="num">
                                <el-input required v-model="forgets.num" placeholder="输入手机号/邮箱" maxlength="30" class="layui-input inputStyle" lay-verType="msg" />
                            </el-form-item>
                            <el-form-item class="layui-form-item margin-top-40" el-form-item prop="code">
                                <el-input type="password" required v-model="forgets.code" placeholder="输入密码" maxlength="30" class="layui-input inputStyle" lay-verType="msg" />
                            </el-form-item>
                            <div class="layui-form-item login-auto margin-top-30" style="height: 20px;">
                                <div class="layui-input-inline" style="margin-left: 30px;"><el-checkbox v-model="checked1">自动登录</el-checkbox></div>
                            </div>
                            <el-button type="primary" @click="handleLogin('forgets')" class="login-btn margin-top-30">登录</el-button>
                            <div style="width: 25rem;box-sizing: border-box;overflow:hidden;margin: 30px auto 10px auto;">
                                <p @click="(signUpTab = true), (hide = false)" class="wjmm fl" style="line-height: 20px; margin-right: 20px;color:#409EFF ;">注册账户</p>
                                <p
                                    @click="
                                        hide = false;
                                        isshow = true;
                                    "
                                    class="fr"
                                    style="cursor: pointer;font-size: 14px;line-height: 20px;display:block;color:#909399"
                                >
                                    忘记密码
                                </p>
                            </div>
                        </div>
                    </el-form>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { getCodeImg, getCode, phoneSignIn, emailSignIn,ForgetPsd,wxBindUser } from '@/api/login';
import Cookies from 'js-cookie';

export default {
    name: 'Login',
    data() {
        var checkPhone = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('手机号不能为空'));
            } else {
                const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
               // console.log(reg.test(value));
                if (reg.test(value)) {
                    callback();
                } else {
                    return callback(new Error('请输入正确的手机号'));
                }
            }
        };
        // 手机/邮箱验证
        var checkNum = (rule, value, callback) => {
            if (!value) {
                return callback(new Error('手机号/邮箱不能为空'));
            } else {
                let isnum = /^\d+$/.test(value);
                if (isnum == true) {
                    const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
                    if (reg.test(value)) {
                        this.numtype = 1;
                        this.phonenumber = value;
                        callback();
                    } else {
                        return callback(new Error('请输入正确的手机号'));
                    }
                } else {
                    let reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
                    let isok = reg.test(value);
                    this.numtype = 2;
                    this.email = value;
                    if (!isok) {
                        return callback(new Error('邮箱格式不正确，请重新输入'));
                    }
                }
            }
        };
        return {
            codeUrl: '',
            cookiePassword: '',
            loginRule: {
                num: [
                    {
                        required: true,
                        trigger: 'blur',
                        message: '手机号不能为空'
                    },
                    { validator: checkNum, trigger: 'blur' }
                ],
                code: [
                    {
                        required: true,
                        trigger: 'blur',
                        message: '密码不能为空'
                    },
                    {
                        required: true,
                        trigger: 'blur',
                        min: 6,
                        max: 20,
                        message: '密码需长度在 6 到 20 个字符之间'
                    },
                    {
                        pattern: /^[A-Za-z0-9u4e00-u9fa5]+$/,
                        message: '不允许输入空格等特殊符号'
                    }
                ]
            },

            forgets: {
                num: '',
                code: ''
            },
            loading: false,
            redirect: undefined,
            //
            loginTab: ['账号绑定'],
            activeClass: 0,
            signUpTab: false,
            hide: true,
            checked1: true,
            checked2: true,
            checked3: true,
            isshow: false,
            phonenumber: '',
            email: '',
            numtype: 1,
            isShow: true,
            count: '',
            timer: null
        };
    },
    components: {},
    watch: {
        $route: {
            handler: function(route) {
                this.redirect = route.query && route.query.redirect;
            },
            immediate: true
        }
    },
    created() {
    },
    methods: {
        // 获取验证码(手机号-登录)
        getCode() {
            let datas = {
                phone: this.loginForm1.phone
            };
            getCode(datas).then(res => {
                console.log(res);
            });
        },
        handleLogin() {
            // this.$refs["forgets"].validate(valid => {
                // if (valid) {
                    let datas = {};
                    if (this.numtype == 1) {
                        datas = {
                            username: this.phonenumber,
                            password: this.forgets.code,
                            openId:'123'
                        };
                    }
                    if (this.numtype == 2) {
                        datas = {
                            email: this.email,
                            password: this.forgets.code,
                        openId:'123'
                        };
                    }
                    wxBindUser(datas).then(res => {
                        // if (res.code === 200) {
                        //     this.msgSuccess("修改成功");
                        //     this.tologin();
                        // } else {
                        //     this.msgError(res.msg);
                        // }
                        // this.$router.push({ path: this.redirect || '/' });
                    });
            //     }
            // });
        },

        onTab(index) {
            this.activeClass = index;
        },
        insuranceInformations() {
            this.signUpTab = false;
            this.hide = true;
        },
        displays() {
            this.hide = true;
            this.isshow = false;
        }
    }
};
</script>

<style rel="stylesheet/scss" lang="scss">
@import '../../assets/styles/global.css';
.login {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}
/* .title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.login-form {
  border-radius: 6px;
  background: #ffffff;
  width: 400px;
  padding: 25px 25px 5px 25px;
  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.login-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.el-login-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  colo r: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
} */
/* 登录 */
body {
    font-size: 62.5% !important;
}

.margin-top-30 {
    margin-top: 1.875rem !important;
}

.login-container {
    /* width: 1920px;
	height: 1080px; */
    width: 100%;
    height: 100%;
    min-height: 760px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    background-image: url('../../assets/image/login-background.jpg');
    background-size: cover;
}

.login-wrap {
    /* width:714px;
	height:883px; */
    width: 44.625rem;
    /* height: 55.1875rem; */
    padding-bottom: 1.875rem;
    background: #ffffff;
    border-radius: 2.5rem;
    border: 0.375rem solid rgba(255, 255, 255, 0.31);
    float: right;
    /* margin-top: 6.125rem; */
    margin-right: 12.5rem;
}

.login-wrap .logo {
    text-align: center;
    padding-top: 2.9375rem;
}

.login-wrap .logo p {
    font-size: 2.375rem;
    font-family: SourceHanSansCN-Bold, SourceHanSansCN;
    font-weight: bold;
    color: rgba(8, 20, 38, 1);
}

.dlfs-ul {
    text-align: center;
    margin-top: 3.5625rem;
}

.dlfs-ul li {
    display: inline-block;
    _display: initial;
    *display: initial;
    *zoom: 1;
    color: #bababa;
    font-size: 1.25rem;
    margin: 0 1rem;
    position: relative;
    padding-bottom: 0.8125rem;
    cursor: pointer;
}

.login .active {
    color: #000000;
}

.login .active:after {
    content: '';
    width: 100%;
    height: 0.25rem;
    background: rgba(0, 0, 0, 1);
    border-radius: 0.125rem;
    position: absolute;
    left: 0;
    bottom: 0;
}
.el-form-item {
}

.layui-form-item {
    margin: 3.75rem auto !important;
    width: 30.875rem;
    height: 5rem;
    border-radius: 40px;
}
.login .el-input--medium .el-input__inner {
    height: 5rem;
    line-height: 5rem;
    border-radius: 40px;
    overflow: hidden;
}

.login .reg-wrap .layui-form-items {
    margin: 2.5rem 0 !important;
}

.reg-wrap .login-auto {
    // margin: 0 9.375rem 0 9.0625rem !important;
}

.layui-form-item .login-list {
    width: 100%;
    height: 5rem;
    line-height: 5rem;
    background: #f8f8f8;
    border-radius: 2.5rem;
    margin: 0 auto;
    float: inherit;
}

.layui-form-item .login-list .layui-input {
    width: 100%;
    height: 100%;
    padding: 0 2.5rem;
    font-size: 1.375rem;
    font-family: SourceHanSansCN-Regular, SourceHanSansCN;
    font-weight: 400;
    color: #cbcbcb;
    background: none;
    border: none;
}

.login-list .hzm {
    width: 19.6875rem !important;
    float: left;
}

.login .hqyzm {
    font-size: 1.375rem;
    color: #3893f3;
    float: left;
    position: absolute;
    top: 7px;
    right: 20px;
    background: transparent;
    border: 0;
    cursor: pointer;
}

.login-list .hqyzm::after {
    content: '';
    width: 0.125rem;
    height: 3.5rem;
    background: rgba(234, 234, 234, 1);
    position: absolute;
    top: 50%;
    margin-top: -1.75rem;
    left: 0;
}

.login-auto {
    margin: 0 auto !important;
}

.login-auto .layui-input-inline input[type='checkbox'] {
    width: 0.9375rem;
    height: 0.9375rem;
    background: #f4f4f4;
    margin-right: 0.625rem;
    font-size: 1.125rem;
    color: #333333;
}

.layui-input-inline {
    float: left;
}
.wjmm {
    font-size: 14px;
    color: #333333;
    display: inline-block;
    cursor: pointer;
}

.login-btn {
    display: block;
    width: 30.875rem;
    height: 5rem;
    background: #3e95f0;
    border-radius: 2.5rem;
    margin: 30px auto 0 auto;
    font-size: 1.625rem;
    font-family: SourceHanSansCN-Medium, SourceHanSansCN;
    font-weight: 500;
    color: #ffffff;
    border: none;
}

.login-auto .qtfs {
}

.login-qtfs {
    margin: 3.625rem 9.375rem 0 7.75rem !important;
}

.login-qtfs .qtfs {
    width: 200px !important;
    line-height: 20px;
    display: inline-block;
}
.login-auto .qtfs > span {
    line-height: 20px;
    display: inline-block;
}
.login-qtfs .qtfs a {
    margin-left: 1.5625rem;
    margin-top: 3px;
    display: inline-block;
    position: relative;
    top: 3px;
}

.login-qtfs .qtfs a img {
    height: 1.625rem;
}

.zhdl {
    text-align: center;
}

.reg-wrap {
    /* height: 62.4375rem; */
    /* margin-top: 2.5rem; */
    padding-bottom: 1.875rem;
}

input::-webkit-input-placeholder {
    /*Webkit browsers*/
    color: #cbcbcb;
}

input:-moz-placeholder {
    /*Mozilla Firefox 4 to 8*/
    color: #cbcbcb;
}

input::moz-placeholder {
    /*Mozilla Firefox 19+*/
    color: #cbcbcb;
}

input:-ms-input-placeholder {
    /*Internet Explorer 10+*/
    color: #cbcbcb;
}
.dlfs-wrap {
    display: none;
}
.inputStyle input {
    background: #f8f8f8 !important;
}
.verification {
    position: relative;
}
#qrcode {
    width: 180px;
    height: 180px;
    margin: 45px auto 0px;
    display: block;
}
#qrcode img {
    width: 100%;
    height: 100%;
}
</style>
